import { run } from './script.ts';
import { parse } from 'https://deno.land/std@0.200.0/flags/mod.ts';

const {_: [entryFilePath], importMap, external, ...rest} = parse(Deno.args);
if (typeof entryFilePath === 'number') throw Error('entryFilePath must be string');
let imports: {[key: string]: string} = {};
if (importMap) {
  if (/^https?:\/\//.test(importMap)) {
    const res = await fetch(importMap);
    imports = await res.json();
  } else {
    imports = JSON.parse(await Deno.readTextFile(importMap));
  }
}

await run(entryFilePath, imports, {external, ...rest});